package com.dream.keigezhushou.Activity.acty;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dream.keigezhushou.Activity.GlobalConst.GlobalConst;
import com.dream.keigezhushou.Activity.Uiutils.PrefUtils;
import com.dream.keigezhushou.Activity.Uiutils.ToastUtils;
import com.dream.keigezhushou.Activity.acty.login.LoginActivity;
import com.dream.keigezhushou.Activity.acty.personal.DiscountActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyAttentionActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyBagActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyBuyCarActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyChorusActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyCollectActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyEvaluateActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyFansActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyGamesActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyKgeActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyOrderActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyPayActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyRefundActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyRingActivity;
import com.dream.keigezhushou.Activity.acty.personal.MyUseActivity;
import com.dream.keigezhushou.Activity.acty.personal.NativeRecordActivity;
import com.dream.keigezhushou.Activity.acty.personal.NewsCenterActivity;
import com.dream.keigezhushou.Activity.acty.personal.PersonalHomepageActivity;
import com.dream.keigezhushou.Activity.acty.personal.SettingActivity;
import com.dream.keigezhushou.Activity.acty.personal.UserInfoActivity;
import com.dream.keigezhushou.Activity.view.CircleImageView;
import com.dream.keigezhushou.Activity.view.NestedScrollViewBottom;
import com.dream.keigezhushou.R;
import com.zhy.autolayout.AutoLayoutActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PersonCenterActivity extends AutoLayoutActivity implements View.OnClickListener {

    @BindView(R.id.iv_user_edit)
    ImageView ivUserEdit;
    @BindView(R.id.tv_user_nick)
    TextView tvUserNick;
    @BindView(R.id.tv_sign)
    TextView tvSign;
    @BindView(R.id.rl_ksong)
    RelativeLayout rlKsong;
    @BindView(R.id.rl_hechang)
    RelativeLayout rlHechang;
    @BindView(R.id.rl_native_record)
    RelativeLayout rlNativeRecord;
    @BindView(R.id.rl_my_fans)
    RelativeLayout rlMyFans;
    @BindView(R.id.rl_my_attention)
    RelativeLayout rlMyAttention;
    @BindView(R.id.rl_my_order)
    LinearLayout rlMyOrder;
    @BindView(R.id.ll_wait_pay)
    LinearLayout llWaitPay;
    @BindView(R.id.ll_wait_use)
    LinearLayout llWaitUse;
    @BindView(R.id.ll_wait_evaluate)
    LinearLayout llWaitEvaluate;
    @BindView(R.id.ll_refund)
    LinearLayout llRefund;
    @BindView(R.id.rl_my_buycar)
    RelativeLayout rlMyBuycar;
    @BindView(R.id.rl_my_collect)
    RelativeLayout rlMyCollect;
    @BindView(R.id.rl_my_bag)
    RelativeLayout rlMyBag;
    @BindView(R.id.rl_discount)
    RelativeLayout rlDiscount;
    @BindView(R.id.rl_my_games)
    RelativeLayout rlMyGames;
    @BindView(R.id.rl_my_ring)
    RelativeLayout rlMyRing;
    @BindView(R.id.rl_news_center)
    RelativeLayout rlNewsCenter;
    @BindView(R.id.scroll_bottom)
    NestedScrollViewBottom scrollBottom;
    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.iv_set)
    ImageView ivSet;
    @BindView(R.id.iv_user_pic)
    CircleImageView ivUserPic;
    @BindView(R.id.rl_no_login)
    RelativeLayout rlNoLogin;
    private Intent intent;
    private boolean isLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_center);
        ButterKnife.bind(this);

        initView();
        initData();

    }

    //初始化界面
    protected void initView() {

        //判断用户有没有登录，加载不同效果
        isLogin = PrefUtils.getBoolean(this, GlobalConst.PREFUL_ISLOGIN, false);

        if (isLogin) {

            //如果登录
            rlNoLogin.setVisibility(View.GONE);
            ivUserPic.setVisibility(View.VISIBLE);
            ivUserEdit.setVisibility(View.VISIBLE);
            tvSign.setVisibility(View.VISIBLE);


        }else {

            //未登录
            ivUserPic.setVisibility(View.GONE);
            rlNoLogin.setVisibility(View.VISIBLE);
            tvUserNick.setText("点击登录");
            tvSign.setVisibility(View.GONE);
            ivUserEdit.setVisibility(View.GONE);

            rlNoLogin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    intent = new Intent(PersonCenterActivity.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
            });

            tvUserNick.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    intent = new Intent(PersonCenterActivity.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
            });
        }
    }

    //初始化数据
    protected void initData() {

        ivReturn.setOnClickListener(this);
        ivSet.setOnClickListener(this);
        ivUserEdit.setOnClickListener(this);
        rlKsong.setOnClickListener(this);
        rlHechang.setOnClickListener(this);
        rlNativeRecord.setOnClickListener(this);
        rlNativeRecord.setOnClickListener(this);
        rlMyFans.setOnClickListener(this);
        rlMyAttention.setOnClickListener(this);

        rlMyOrder.setOnClickListener(this);

        llWaitPay.setOnClickListener(this);
        llWaitUse.setOnClickListener(this);
        llWaitEvaluate.setOnClickListener(this);
        llRefund.setOnClickListener(this);

        rlMyBuycar.setOnClickListener(this);
        rlMyCollect.setOnClickListener(this);
        rlMyBag.setOnClickListener(this);
        rlDiscount.setOnClickListener(this);
        rlMyGames.setOnClickListener(this);
        rlMyRing.setOnClickListener(this);
        rlNewsCenter.setOnClickListener(this);

        ivUserPic.setOnClickListener(this);


        scrollBottom.setScrollBottomListener(new NestedScrollViewBottom.ScrollBottomListener() {
            @Override
            public void scrollBottom() {
                //滑动到底部的监听的实现
            }
        });
    }

    //点击事件的实现

    @Override
    public void onClick(View view) {


        switch (view.getId()) {

            case R.id.iv_return:

                finish();
                break;

            case R.id.iv_set:

                //设置界面
                if (isLogin){

                    intent = new Intent(this, SettingActivity.class);
                    startActivity(intent);
                    finish();
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.iv_user_pic:

                //个人主页

                if (isLogin){

                    intent = new Intent(this, PersonalHomepageActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.iv_user_edit:

                //个人中心
                if (isLogin){

                    intent = new Intent(this, UserInfoActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.rl_ksong:

                //K歌

                if (isLogin){

                    intent = new Intent(this, MyKgeActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;


            case R.id.rl_hechang:

                //合唱

                if (isLogin){

                    intent = new Intent(this, MyChorusActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;


            case R.id.rl_native_record:

                //录音

                if (isLogin){

                    intent = new Intent(this, NativeRecordActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }


                break;


            case R.id.rl_my_fans:

                //粉丝

                if (isLogin){

                    intent = new Intent(this, MyFansActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;


            case R.id.rl_my_attention:

                //关注

                if (isLogin){

                    intent = new Intent(this, MyAttentionActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.rl_my_order:

                //订单

                if (isLogin){

                    intent = new Intent(this, MyOrderActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.ll_wait_pay:

                //待付款

                if (isLogin){

                    intent = new Intent(this, MyPayActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.ll_wait_use:

                //待使用
                if (isLogin){

                    intent = new Intent(this, MyUseActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.ll_wait_evaluate:

                //待评价
                if (isLogin){

                    intent = new Intent(this, MyEvaluateActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.ll_refund:

                //退款
                if (isLogin){

                    intent = new Intent(this, MyRefundActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.rl_my_buycar:

                //购物车

                if (isLogin){

                    intent = new Intent(this, MyBuyCarActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.rl_my_collect:

                //收藏
                if (isLogin){

                    intent = new Intent(this, MyCollectActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.rl_my_bag:

                //钱包
                if (isLogin){

                    intent = new Intent(this, MyBagActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.rl_discount:

                //优惠券
                if (isLogin){

                    intent = new Intent(this, DiscountActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.rl_my_games:

                //城会玩

                if (isLogin){

                    intent = new Intent(this, MyGamesActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.rl_my_ring:

                //消息中心

                if (isLogin){

                    intent = new Intent(this, MyRingActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;

            case R.id.rl_news_center:

                //消息中心

                if (isLogin){

                    intent = new Intent(this, NewsCenterActivity.class);
                    startActivity(intent);
                }else {

                    ToastUtils.showToast(this,"您未登录，请先登录");
                }

                break;


        }
    }
}
